public class Tree0 {
    public Tree treeNode=null;
    public Tree t;
    public void add(Tree x){
        if(treeNode==null){
            treeNode=x;
        }else{
            t=treeNode;
            while (t!=null){
                if(x.value<t.value){
                    if(t.left==null){
                        t.left=x;
                        break;
                    }else{
                        t=t.left;
                    }
                }else{
                    if(t.right==null){
                        t.right=x;
                        break;
                    }else{
                        t=t.right;
                    }
                }
            }
        }
    }

    public void firstOut(Tree x){
        if(x!=null){
            System.out.print(x.value+"   ");
            firstOut(x.left);
            firstOut(x.right);
        }
    }
    public void midOut(Tree x){
        if(x!=null){
            midOut(x.left);
            System.out.print(x.value+"   ");
            midOut(x.right);
        }
    }
    public void lastOut(Tree x){
        if(x!=null){
            lastOut(x.left);
            lastOut(x.right);
            System.out.print(x.value+"   ");
        }
    }
    public void layerlayerOut(Tree x){
        QueueDemo<Tree> q=new QueueDemo<Tree>();
        if(x==null){
            System.out.println("空");
        }else{
            q.add(x);
            while(!q.contains()){
                Tree tt=q.get();
                System.out.print(tt.value+"   ");
                if(tt.left!=null){
                    q.add(tt.left);
                }
                if(tt.right!=null){
                    q.add(tt.right);
                }
            }
        }
    }
}
